<%--
  Created by IntelliJ IDEA.
  User: wwh
  Date: 2017/8/9
  Time: 11:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>行政管理人员</title>
    <link rel="stylesheet" href="../../static/common/layui/css/layui.css">
    <link rel="stylesheet" href="../../static/css/global.css">
    <link rel="stylesheet" href="../../static/css/table.css">
</head>
<body>
<div style="margin:15px;" id="Vue">
    <div v-show="show">
        <blockquote class="layui-elem-quote">
            <a href="#" class="layui-btn layui-btn-small" @click="addAdministration">
                <i class="layui-icon">&#xe608;</i> 创建行政管理人员
            </a>
        </blockquote>
        <fieldset class="layui-elem-field">
            <legend>行政管理人员信息</legend>
            <div class="layui-field-box layui-form">
                <table class="layui-table admin-table">
                    <thead>
                    <tr>
                        <th>账号</th>
                        <th>姓名</th>
                        <th>工号</th>
                        <th>系部</th>
                        <th>办公电话</th>
                        <%--<th>私人电话</th>--%>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <%--内容容器--%>
                    <tbody id="content">
                    </tbody>
                </table>
            </div>
        </fieldset>
        <%--分页容器--%>
        <div class="admin-table-page">
            <div id="paged" class="page">
            </div>
        </div>
    </div>

    <div v-show="!show" style="display: none;">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>行政人员信息</legend>
            <div class="layui-form-item">
                <label class="layui-form-label">真实姓名</label>
                <div class="layui-input-inline">
                    <input class="layui-input" v-model="user.realname" disabled>
                </div>
                <label class="layui-form-label">工号</label>
                <div class="layui-input-inline">
                    <input class="layui-input" v-model="user.workid" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-block">
                    <div v-if="user.sex == 1">
                        <label class="layui-form-label" style="color: #999">男</label>
                    </div>
                    <div v-else="user.sex == 2">
                        <label class="layui-form-label" style="color: #999">女</label>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱地址</label>
                <div class="layui-input-inline">
                    <input type="email" name="email" v-model="user.email" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">私人电话</label>
                <div class="layui-input-inline">
                    <input type="text" v-model="user.mobilephone" class="layui-input" readOnly>
                </div>
                <label class="layui-form-label">办公电话</label>
                <div class="layui-input-inline">
                    <input type="text" v-model="magFacultyInfo.phone" class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">私人QQ</label>
                <div class="layui-input-inline">
                    <input type="text" v-model="user.qq" class="layui-input" disabled>
                </div>
                <label class="layui-form-label">办公QQ</label>
                <div class="layui-input-inline">
                    <input type="text" v-model="magFacultyInfo.qq" class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">私人微信</label>
                <div class="layui-input-inline">
                    <input type="email" v-model="user.wechat" class="layui-input" disabled>
                </div>
                <label class="layui-form-label">办公微信</label>
                <div class="layui-input-inline">
                    <input type="email" v-model="magFacultyInfo.wechat" class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">所在系部</label>
                <div class="layui-input-inline">
                    <input class="layui-input" v-model="department.name" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="button" class="layui-btn layui-btn-normal" @click="reload" value="返回">
                </div>
            </div>
        </fieldset>
    </div>
</div>
<script type="text/javascript" src="/static/common/layui/layui.js"></script>
<script type="text/javascript" src="/static/common/vue.min.js"></script>
<script type="text/javascript" src="/static/common/axios.min.js"></script>
<script>
    var userId = ${sessionScope.currentUser.getId()};
    var schoolAdmin = {};
    axios.get('/schoolMangerInfo/findByUserId/'+userId)
        .then(function (response) {
            schoolAdmin = response.data.data;
        })
        .catch(function (msg) {
            console.log(msg);
        });
</script>
<!--分页模板-->
<script type="text/html" id="tpl">
    {{# layui.each(d.data,function(index,item){ }}
    <tr>
        <td>{{ item.magfacultyInfoDetail.user.username || "--" }}</td>
        <td>{{ item.magfacultyInfoDetail.user.realname || "--" }}</td>
        <td>{{ item.magfacultyInfoDetail.user.workid || "--" }}</td>
        <td>{{ item.department.name || "--" }}</td>
        <td>{{ item.magfacultyInfoDetail.magFacultyInfo.phone || "--" }}</td>
        <%--<td>{{ item.magfacultyInfoDetail.user.mobilephone || "--" }}</td>--%>
        <td>
            <a href="javascript:;" target="_self" data-id="{{item.magfacultyInfoDetail.user.id}}" data-opt="detail" class="layui-btn layui-btn-mini">详情</a>
            <a href="javascript:;" target="_self" data-id="{{item.magfacultyInfoDetail.user.id}}" data-opt="remove" class="layui-btn layui-btn-danger layui-btn-mini">删除</a>
        </td>
    </tr>
    {{# }); }}
</script>
<script>
    layui.config({
        base: '/static/js/layuiModulesEX/'
    });
    layui.use(['paging', 'form', 'layer','formverify'],function () {
        var $ = layui.jquery,
            paging = layui.paging(),
            layer = layui.layer,
            form = layui.form(),
            formverify = layui.formverify;

        var vm = new Vue({
            el:"#Vue",
            data:{
                show:true,
                user:{},
                magFacultyInfo:{
                    schoolid:schoolAdmin.schoolid
                },
                school:{},
                department:{},
                university:{}
            },
            methods:{
                /**
                 * 创建行政管理员
                 */
                addAdministration:function () {
                    console.log(123);
                    $.get('/schoolAdmin/addAdministration',null,function (html) {
                        layer.open({
                            type:1,
                            title:"添加行政人员",
                            area: ['600px', '400px'],
                            content:html,
                            success:function (layero,index) {
                                form.on("submit(create)",function (data) {
                                    console.log(data);
                                    axios.get('/user/checkUserName/'+data.field.username)
                                        .then(function (response) {
                                            console.log(response.data);
                                            if(response.data.success){
                                                top.layer.msg("用户名已存在");
                                            }
                                            else{
                                                var administrationDetail = {
                                                    User:{
                                                        username:data.field.username,
                                                        password:data.field.password,
                                                        usertype:3
                                                    },
                                                    MagFacultyInfo:{
                                                        schoolid:schoolAdmin.schoolid,
                                                        divisionid:data.field.departmentid
                                                    }
                                                };
                                                console.log(administrationDetail);
                                                axios.post('/magfacultyinfo/addOne',administrationDetail)
                                                    .then(function (response) {
                                                        paging.get();
                                                        layer.msg(response.data.message);
                                                        layer.close(index);
                                                    })
                                                    .catch(function (msg) {
                                                        console.log(msg);
                                                    })
                                            }
                                        })
                                        .catch(function (msg) {
                                            console.log(msg);
                                        })
                                    return false;
                                });
                                return false;
                            },
                            end:function (layero,index) {
                                layer.close(index);
                            }
                        });
                    });
                },
                /**
                 * 返回
                 */
                reload:function () {
                    vm.show=true;
                }
            }
        });

        paging.init({
            openWait:true,
            url:'/magfacultyinfo/findBatchByCondition',
            elem:"#content",
            params:{
                schoolid:schoolAdmin.schoolid
            },
            contentType: "application/json; charset=utf-8",
            type: 'POST',
            tempElem: '#tpl', //模块容器
            pageConfig: { //分页参数配置
                elem: 'paged', //分页容器
                pageSize: 10 //分页大小
            },
            success:function () {
                // alert('渲染成功');
            },
            fail:function () {
                // alert('获取数据失败')
            },
            complate:function () {
                // alert('处理完成');
                $("#content").children('tr').each(function () {
                    var $that = $(this).children('td:last-child');
                    var magFacultyInfo_userid = $that.children('a[data-opt=detail]').data('id');
                    console.log(magFacultyInfo_userid);

                    $that.children('a[data-opt=detail]').on('click',function () {
                        axios.get('/magfacultyinfo/findOne/'+magFacultyInfo_userid)
                            .then(function (response) {
                                console.log(response.data);
                                vm.user = response.data.data.user;
                                vm.magFacultyInfo = response.data.data.magFacultyInfo;
                                vm.school = response.data.data.school;
                                vm.department = response.data.data.department;
                                vm.university = response.data.data.university;
                                vm.show = false;
                            })
                            .catch(function (msg) {
                                console.log(msg);
                            })
                    });

                    $that.children('a[data-opt=remove]').on('click',function () {
                        console.log(administration_userid);
                        layer.confirm("确认删除？",function () {
                            axios.get('/magfacultyinfo/removeOneByUserId/'+magFacultyInfo_userid)
                                .then(function (response) {
                                    console.log(response.data);
                                    paging.get();
                                    layer.msg(response.data.message);
                                })
                                .catch(function (msg) {
                                    console.log(msg);
                                })
                        });
                    });
                });
            }
        })
    });
</script>
</body>
</html>
